package cn.tedu.boot24.controller;

import cn.tedu.boot24.entity.Hero;
import cn.tedu.boot24.mapper.HeroMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
public class HeroController {
    @Autowired(required = false)
    HeroMapper mapper;

    //添加英雄操作
    @RequestMapping("/add")
    @ResponseBody
    public String add(Hero hero) {
        System.out.println("hero = " + hero);
        mapper.insert(hero);
        return "英雄添加完成!";
    }

    //删除英雄操作
    @RequestMapping("/delete")
    @ResponseBody
    public String delete(String name) {
        System.out.println("name = " + name);
        mapper.deleteByName(name);
        return "删除英雄完成!";
    }

    //修改英雄操作
    @RequestMapping("/update")
    @ResponseBody
    public String update(Hero hero) {
        System.out.println("hero = " + hero);
        mapper.update(hero);
        return "修改英雄完成!";
    }

    //查询英雄操作
    @RequestMapping("/select")
    @ResponseBody
    public String select() {
        List<Hero> list = mapper.select();
        return list.toString();
    }


}
